package com.awenhui.demo.core.utils;

import java.util.Calendar;
import java.util.Date;

/**
 * @author yuxf
 * @version 1.0
 * @date 2020/5/12 15:48
 */
public class DateUtils {


    /**
     * 获取星期
     * @param date
     * @return 1-7,1-星期日，7-星期六，其他依次类推
     */
    public int getWeekIndex(Date date)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int weekIndex = calendar.get(Calendar.DAY_OF_WEEK);
        return weekIndex;
    }

    /**
     * 获取星期字符串表示
     * @param weekIndex
     * @return
     */
    public String GetWeekStr(int weekIndex)
    {
        String weekStr="";
        switch (weekIndex){
            case 1:
                weekStr="星期日";
                break;
            case 2:
                weekStr="星期一";
                break;
            case 3:
                weekStr="星期二";
                break;
            case 4:
                weekStr="星期三";
                break;
            case 5:
                weekStr="星期四";
                break;
            case 6:
                weekStr="星期五";
                break;
            case 7:
                weekStr="星期六";
                break;
        }
        return weekStr;
    }
}
